package org.wesc.boot.service.websocket;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.wesc.boot.common.base.BaseMap;

/**
 * redis客户端
 * @author Wesley
 */
@Configuration
public class WebSocketRedisClient {

    private final RedisTemplate redisTemplate;

    @Autowired
    public WebSocketRedisClient(RedisTemplate redisTemplate) {
        this.redisTemplate = redisTemplate;
    }


    /**
     * 发送消息
     *
     * @param handlerName
     * @param params
     */
    public void sendMessage(String handlerName, BaseMap params) {
        params.put(WebSocketConstant.HANDLER_NAME, handlerName);
        redisTemplate.convertAndSend(WebSocketConstant.REDIS_TOPIC_NAME, params);
    }


}
